/**
 * 
 */
package br.com.agoravai16072011.conf;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @author jleite
 *
 */
public class HibernateFactory{

	
	
	/**
	 * 
	 */
	private HibernateFactory() {
	}
	
	
	
	private static Configuration configuration = null;
	private static SessionFactory factory = null;

	public static Configuration getConfiguration(){
		
		
		configuration = new Configuration();
		//configuration.addClass(Project.class); // it�s already configured in hibernate.cfg.xml
		configuration.configure("brisa.hibernate.cfg.xml");
		return configuration;
	}

	public static SessionFactory getInstance()
	{
		if(factory == null) {
			//factory = getConfiguration().configure("brisa.hibernate.cfg.xml").buildSessionFactory();
			factory = getConfiguration().buildSessionFactory();
		}
		return factory;
	}
	
	
	public static Session getSession(){
		if(factory == null)factory = getInstance();
		return factory.openSession();
	}
}
